import { Label } from 'cc';
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('UIWait')
export class UIWait extends Component {
    @property(Node)
    public ani: Node;

    @property(Label)
    public label: Label;

    private static _aniOriginEulerZ: number = null;

    protected onLoad(): void {
        if (UIWait._aniOriginEulerZ == null) {
            UIWait._aniOriginEulerZ = this.ani.eulerZ;
        }
    }

    protected onEnable(): void {
        this.node.setSiblingIndex(this.node.parent.children.length);
        if (UIWait._aniOriginEulerZ != null) {
            this.ani.eulerZ = UIWait._aniOriginEulerZ;
        }
    }

    protected start(): void {
        this.ani.DORotateZ(0.5, -90)
            .repeatForever()
            .start();
    }

    public show(text?: string) {
        this.label.string = text ?? '';
    }
}